﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Web.UI.HtmlControls;

using AjaxControlToolkit;
using BizElements.Core;
using BizElements.BusinessLayer;

namespace BizElements.Web
{
    /// <summary>Component that edits and displays a collection of business objects.</summary>
    public interface ICollectionEditor
    {
        #region Methods.

        /// <summary>Adds new business objects to collection and edits them.</summary>
        /// <param name="newItems">New objects. Ensure that all required but non-editable fields have been set to valid values before calling this method.</param>
        void AddItems(params ISelfValidatingObject[] newItems);

        /// <summary>Checks if new or edited items have been submited/accepted and whether they contain erros.</summary>
        /// <value><b>false</b> if errors are found or if the component hasn't accepted current changes; otherwise <b>true</b></value>
        bool HasErrors();

        /// <summary>Checks if there are any new of edited items that haven't submitted and accepted..</summary>
        /// <value><b>true</b> if there are unsubmitted items.</value>
        bool HasUnsubmittedChanges();

        /// <summary>Hides all butons, ie. sets their Visible property to <b>false</b>.</summary>
        void HideAllButtons();

        /// <summary>Refreshes the control and rebinds the collection.</summary>
        void Refresh();

        /// <summary>Rejects all new and currently edited items that haven't been accepted yet.</summary>
        void RejectUnsubmittedChanges();

        #endregion

        #region Properties.

        /// <summary>Indicates whether all items and all fields are always in edit mode, ie. spreadsheet-like mode.</summary>
        bool AlwaysEditBoundFields { get; set; }

        /// <summary>Control title.</summary>
        string Caption { get; set; }

        /// <summary>Collection of bound business objects that implement <see cref="BizElements.BusinessLayer.ISelfValidatingObject"/> interface.</summary>
        IList Collection { get; set; }

        /// <summary>Programatic identifier assigned to control.</summary>
        string ID { get; }

        /// <summary>Indicates whether the component is in read-only mode.</summary>
        bool ReadOnly { get; set; }

        /// <summary>Gets the selected key values. There may be more than one value if the controls implements multi-row select mode.</summary>
        string[] SelectedValues { get; }

        /// <summary>Indicates whether a control is rendered as UI on the page.</summary>
        bool Visible { get; set; }

        #endregion

        #region Events - commented. Maybe add in future.

        //event CancelCommandEventHandler BeginEditing;
        //event CancelCommandEventHandler BeginInserting;
        //event CommandEventHandler BindFields;        
        //event CommandEventHandler CollectionChanged;        
        //event CommandEventHandler ConvertCollectionItemsToBusinessObject;
        //event CommandEventHandler ItemPicked;
        //event CommandEventHandler NewItem;        
        //event CommandEventHandler OpenDetails;        
        //event CommandEventHandler RefetchCollection;        
        //event CommandEventHandler SaveCollection;

        #endregion
    }
}
